# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: team/kde <bribbers@disroot.org>

# The group tag is just to easily find this APKBUILD by some scripts for automation
# group=kde-plasma
pkgname=powerdevil
pkgver=5.27.10
pkgrel=0
pkgdesc="Manages the power consumption settings of a Plasma Shell"
# armhf blocked by extra-cmake-modules
arch="all !armhf"
url="https://kde.org/plasma-desktop/"
license="GPL-2.0-or-later AND LGPL-2.0-or-later AND (LGPL-2.1-only OR LGPL-3.0-only)"
depends="upower"
depends_dev="
	bluez-qt5-dev
	ddcutil-dev
	eudev-dev
	kactivities5-dev
	kauth5-dev
	kconfig5-dev
	kcrash5-dev
	kdbusaddons5-dev
	kglobalaccel5-dev
	ki18n5-dev
	kidletime5-dev
	kio5-dev
	knotifications5-dev
	knotifyconfig5-dev
	kwayland5-dev
	libkscreen-dev
	networkmanager-qt5-dev
	plasma-workspace-dev
	qt5-qtbase-dev
	qt5-qtx11extras-dev
	solid5-dev
	"
makedepends="$depends_dev
	extra-cmake-modules
	kdoctools5-dev
	libcap-utils
	samurai
	"

case "$pkgver" in
	*.90*) _rel=unstable;;
	*) _rel=stable;;
esac
_repo_url="https://invent.kde.org/plasma/powerdevil.git"
source="https://download.kde.org/$_rel/plasma/$pkgver/powerdevil-$pkgver.tar.xz"
subpackages="$pkgname-dev $pkgname-libs $pkgname-doc $pkgname-lang"

build() {
	# HAVE_DDCUTIL needs to be set manually for now but is enabled by default in the next
	# (post 5.28.x) powerdevil version. Nothing changed in particular warranting it to be
	# enabled again, but upstream mentions the reasons for originally disabling it by default
	# aren't known anymore and it's time to re-enable again
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DHAVE_DDCUTIL=ON
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# We don't ship systemd
	rm -r "$pkgdir"/usr/lib/systemd

	# org_kde_powerdevil has CAP_WAKE_ALARM set and this breaks dbus
	# Remove CAP_WAKE_ALARM from org_kde_powerdevil to make it work again
	setcap -r "$pkgdir"/usr/lib/libexec/org_kde_powerdevil
}

sha512sums="
7bee5e98e5e1cedfc94c7e5d5296c88a88269f2838bb937073bd27cd0bc0ee696ae7134386ea84ea60b8ed18c5bdb6d2a715fd599c0836d62a3191183a47d47e  powerdevil-5.27.10.tar.xz
"
